// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import Vuex from 'vuex';
import Axios from 'axios';
import App from './App';
import goods from './components/goods/goods.vue';
import 'common/stylus/index.styl';
Axios.interceptors.request.use(
  config => {
    console.log(config)
    // 在发送请求之前做某件事
    if (
      config.method === "post"
    ) {
      config.url += `?access_token = ${localStorage.access_token}`;
      // 序列化
      console.log(JSON.stringify(config.data))
      config.data = 'data='+JSON.stringify(config.data);
      // 温馨提示,若是贵公司的提交能直接接受json 格式,可以不用 qs 来序列化的
    }else{
      // config.url += `&access_token = ${localStorage.access_token}`;
    }

    // 若是有做鉴权token , 就给头部带上token
    // 若是需要跨站点,存放到 cookie 会好一点,限制也没那么多,有些浏览环境限制了 localstorage 的使用
    if (localStorage.access_token) {
      // config.headers.Authorization = localStorage.access_token;
    }
    console.log(config)
    return config;
  },
  error => {
    // error 的回调信息,看贵公司的定义
    return Promise.reject(error.data.error.message);
  }
);
Vue.prototype.$http = Axios;

import {
  store
} from './store/store.js'

window.idInfo = {
  store_id: '',
  dest_id: ''
}

Vue.filter('format-dollar',function(value){
  return `$${value}`
})

// Vue.use(VueResource);
new Vue({
  el: '#app',
  store,
  components: { App },
  template: '<App/>'
})
